package com.zzh.takeoutapp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.base.MyBaseAdapter;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/8/2.
 */

public class AddLocationAdapter extends MyBaseAdapter<PoiInfo, RecyclerView.ViewHolder> {
    private Context mContext;
    private List<PoiInfo> poiInfoList;
    public static final int MIN_CLICK_DELAY_TIME = 1500;
    private long lastClickTime = 0;

    public AddLocationAdapter(List<PoiInfo> list, Context context) {
        super(list, context);
        this.mContext = context;
        this.poiInfoList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup container, int type) {
        return new ViewOneHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_add_location, container, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (lis != null) {
                    long currentTime = System.currentTimeMillis();
                    if (currentTime - MIN_CLICK_DELAY_TIME > lastClickTime) {
                        lastClickTime = System.currentTimeMillis();
                        lis.onItemClick(view, null, position);
                    }
                }
            }
        });
        PoiInfo poiInfo = poiInfoList.get(position);
        if (holder instanceof ViewOneHolder) {
            ((ViewOneHolder) holder).tvAddress.setText(poiInfo.address);
            ((ViewOneHolder) holder).tvCity.setText(poiInfo.name);
        }

    }

    //普通的Holder
    public class ViewOneHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.address)
        TextView tvAddress;
        @Bind(R.id.city)
        TextView tvCity;

        public ViewOneHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
